{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "key_luo =\"4996cc7eec646bf7fe2d0855069cf43f\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def walking(origin,destination,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/direction/walking?parameters'\n",
    "    params={\n",
    "        'key':key_luo,\n",
    "        'origin':origin,\n",
    "        'destination':destination,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def geocode(address,city=None,batch=None,sig=None)->dict:\n",
    "    \"\"\"获取地理编码\"\"\"\n",
    "    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'\n",
    "    params={\n",
    "        'key': key_luo,\n",
    "        'address':address,\n",
    "        'city':city,\n",
    "        'batch':batch,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'count': '1',\n",
       " 'geocodes': [{'formatted_address': '河南省郑州市二七区郑州大学',\n",
       "   'country': '中国',\n",
       "   'province': '河南省',\n",
       "   'citycode': '0371',\n",
       "   'city': '郑州市',\n",
       "   'district': '二七区',\n",
       "   'township': [],\n",
       "   'neighborhood': {'name': [], 'type': []},\n",
       "   'building': {'name': [], 'type': []},\n",
       "   'adcode': '410103',\n",
       "   'street': [],\n",
       "   'number': [],\n",
       "   'location': '113.636423,34.745966',\n",
       "   'level': '兴趣点'}]}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "郑大 = geocode(address='河南省郑州市二七区郑州大学')\n",
    "郑大"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(起点)郑大_location: 113.636423,34.745966 (终点)四十七中_location: 113.687847,34.806832\n"
     ]
    }
   ],
   "source": [
    "四十七中 = geocode('河南省郑州市金水区第四十七中学')\n",
    "四十七中_location = 四十七中['geocodes'][0]['location']\n",
    "郑大_location = 郑大['geocodes'][0]['location']\n",
    "print(\"(起点)郑大_location:\",郑大_location,\"(终点)四十七中_location:\",四十七中_location)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>orientation</th>\n",
       "      <th>road</th>\n",
       "      <th>distance</th>\n",
       "      <th>duration</th>\n",
       "      <th>polyline</th>\n",
       "      <th>action</th>\n",
       "      <th>assistant_action</th>\n",
       "      <th>walk_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>向北步行80米右转</td>\n",
       "      <td>北</td>\n",
       "      <td>[]</td>\n",
       "      <td>80</td>\n",
       "      <td>64</td>\n",
       "      <td>113.636337,34.746155;113.636337,34.746727;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>向东步行13米左转</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>13</td>\n",
       "      <td>10</td>\n",
       "      <td>113.63635,34.746879;113.63648,34.746914</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>向北步行49米右转</td>\n",
       "      <td>北</td>\n",
       "      <td>[]</td>\n",
       "      <td>49</td>\n",
       "      <td>39</td>\n",
       "      <td>113.63648,34.746914;113.636497,34.747231;113.6...</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沿中原东路向东步行2406米向右前方行走</td>\n",
       "      <td>东</td>\n",
       "      <td>中原东路</td>\n",
       "      <td>2406</td>\n",
       "      <td>1925</td>\n",
       "      <td>113.636497,34.747361;113.637739,34.747365;113....</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>向东步行202米向右前方行走</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>202</td>\n",
       "      <td>162</td>\n",
       "      <td>113.661923,34.751354;113.66217,34.751302;113.6...</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>步行397米左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>397</td>\n",
       "      <td>318</td>\n",
       "      <td>113.663976,34.751905;113.664345,34.751866;113....</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>沿人民路向东北步行1508米向左前方行走</td>\n",
       "      <td>东北</td>\n",
       "      <td>人民路</td>\n",
       "      <td>1508</td>\n",
       "      <td>1206</td>\n",
       "      <td>113.667257,34.752921;113.667752,34.753138;113....</td>\n",
       "      <td>向左前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>沿人民路向东北步行259米左转</td>\n",
       "      <td>东北</td>\n",
       "      <td>人民路</td>\n",
       "      <td>259</td>\n",
       "      <td>207</td>\n",
       "      <td>113.679661,34.76201;113.679709,34.762083;113.6...</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>沿金水路向西步行22米右转</td>\n",
       "      <td>西</td>\n",
       "      <td>金水路</td>\n",
       "      <td>22</td>\n",
       "      <td>18</td>\n",
       "      <td>113.681675,34.763615;113.681528,34.763581;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>步行47米右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>47</td>\n",
       "      <td>38</td>\n",
       "      <td>113.681432,34.763568;113.68145,34.763989</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>沿金水路向东步行34米向左前方行走</td>\n",
       "      <td>东</td>\n",
       "      <td>金水路</td>\n",
       "      <td>34</td>\n",
       "      <td>27</td>\n",
       "      <td>113.68145,34.763989;113.681723,34.763997;113.6...</td>\n",
       "      <td>向左前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>沿花园路向北步行868米右转</td>\n",
       "      <td>北</td>\n",
       "      <td>花园路</td>\n",
       "      <td>868</td>\n",
       "      <td>694</td>\n",
       "      <td>113.681806,34.764054;113.681823,34.764314;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>向东步行526米向左前方行走</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>526</td>\n",
       "      <td>421</td>\n",
       "      <td>113.681997,34.771927;113.682118,34.771966;113....</td>\n",
       "      <td>向左前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>沿政七街向北步行2781米右转</td>\n",
       "      <td>北</td>\n",
       "      <td>政七街</td>\n",
       "      <td>2781</td>\n",
       "      <td>2225</td>\n",
       "      <td>113.687309,34.772496;113.687309,34.773281;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>沿鑫苑路向东步行106米左转</td>\n",
       "      <td>东</td>\n",
       "      <td>鑫苑路</td>\n",
       "      <td>106</td>\n",
       "      <td>85</td>\n",
       "      <td>113.687804,34.797808;113.688854,34.797648;113....</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>沿金明路向北步行1014米到达目的地</td>\n",
       "      <td>北</td>\n",
       "      <td>金明路</td>\n",
       "      <td>1014</td>\n",
       "      <td>811</td>\n",
       "      <td>113.688954,34.797626;113.688898,34.799362;113....</td>\n",
       "      <td>[]</td>\n",
       "      <td>到达目的地</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             instruction orientation  road distance duration  \\\n",
       "0              向北步行80米右转           北    []       80       64   \n",
       "1              向东步行13米左转           东    []       13       10   \n",
       "2              向北步行49米右转           北    []       49       39   \n",
       "3   沿中原东路向东步行2406米向右前方行走           东  中原东路     2406     1925   \n",
       "4         向东步行202米向右前方行走           东    []      202      162   \n",
       "5               步行397米左转          []    []      397      318   \n",
       "6   沿人民路向东北步行1508米向左前方行走          东北   人民路     1508     1206   \n",
       "7        沿人民路向东北步行259米左转          东北   人民路      259      207   \n",
       "8          沿金水路向西步行22米右转           西   金水路       22       18   \n",
       "9                步行47米右转          []    []       47       38   \n",
       "10     沿金水路向东步行34米向左前方行走           东   金水路       34       27   \n",
       "11        沿花园路向北步行868米右转           北   花园路      868      694   \n",
       "12        向东步行526米向左前方行走           东    []      526      421   \n",
       "13       沿政七街向北步行2781米右转           北   政七街     2781     2225   \n",
       "14        沿鑫苑路向东步行106米左转           东   鑫苑路      106       85   \n",
       "15    沿金明路向北步行1014米到达目的地           北   金明路     1014      811   \n",
       "\n",
       "                                             polyline  action  \\\n",
       "0   113.636337,34.746155;113.636337,34.746727;113....      右转   \n",
       "1             113.63635,34.746879;113.63648,34.746914      左转   \n",
       "2   113.63648,34.746914;113.636497,34.747231;113.6...      右转   \n",
       "3   113.636497,34.747361;113.637739,34.747365;113....  向右前方行走   \n",
       "4   113.661923,34.751354;113.66217,34.751302;113.6...  向右前方行走   \n",
       "5   113.663976,34.751905;113.664345,34.751866;113....      左转   \n",
       "6   113.667257,34.752921;113.667752,34.753138;113....  向左前方行走   \n",
       "7   113.679661,34.76201;113.679709,34.762083;113.6...      左转   \n",
       "8   113.681675,34.763615;113.681528,34.763581;113....      右转   \n",
       "9            113.681432,34.763568;113.68145,34.763989      右转   \n",
       "10  113.68145,34.763989;113.681723,34.763997;113.6...  向左前方行走   \n",
       "11  113.681806,34.764054;113.681823,34.764314;113....      右转   \n",
       "12  113.681997,34.771927;113.682118,34.771966;113....  向左前方行走   \n",
       "13  113.687309,34.772496;113.687309,34.773281;113....      右转   \n",
       "14  113.687804,34.797808;113.688854,34.797648;113....      左转   \n",
       "15  113.688954,34.797626;113.688898,34.799362;113....      []   \n",
       "\n",
       "   assistant_action walk_type  \n",
       "0                []         0  \n",
       "1                []         0  \n",
       "2                []         0  \n",
       "3                []         0  \n",
       "4                []         0  \n",
       "5                []         5  \n",
       "6                []         0  \n",
       "7                []         0  \n",
       "8                []         0  \n",
       "9                []         1  \n",
       "10               []         0  \n",
       "11               []         0  \n",
       "12               []         0  \n",
       "13               []         0  \n",
       "14               []         0  \n",
       "15            到达目的地         0  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "0                向北步行80米右转\n",
       "1                向东步行13米左转\n",
       "2                向北步行49米右转\n",
       "3     沿中原东路向东步行2406米向右前方行走\n",
       "4           向东步行202米向右前方行走\n",
       "5                 步行397米左转\n",
       "6     沿人民路向东北步行1508米向左前方行走\n",
       "7          沿人民路向东北步行259米左转\n",
       "8            沿金水路向西步行22米右转\n",
       "9                  步行47米右转\n",
       "10       沿金水路向东步行34米向左前方行走\n",
       "11          沿花园路向北步行868米右转\n",
       "12          向东步行526米向左前方行走\n",
       "13         沿政七街向北步行2781米右转\n",
       "14          沿鑫苑路向东步行106米左转\n",
       "15      沿金明路向北步行1014米到达目的地\n",
       "Name: instruction, dtype: object"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "郑大_四十七中 = walking(郑大_location,四十七中_location)\n",
    "df_步行路径规划 = pd.json_normalize(郑大_四十七中[\"route\"][\"paths\"][0]['steps'])\n",
    "display(df_步行路径规划)\n",
    "df_步行路径规划[\"instruction\"]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
